<template>
  <div class="live-card">
    <template v-if="liveUrl && liveUrl.length>0">
      <div class="pic link" @click="redirectTo(`${liveUrl}`)">
        <img crossorigin="anonymous" :src="liveImg" />
      </div>
      <div class="name link" :title="liveTitle" @click="redirectTo(`${liveUrl}`)">{{liveTitle}}</div>
    </template>
    <template v-else>
      <div class="pic">
        <img crossorigin="anonymous" :src="liveImg" />
      </div>
      <div class="name" :title="liveTitle">{{liveTitle}}</div>
    </template>
  </div>
</template>

<script>
import { useNavigation } from "@utils/navigation";

export default {
  name: 'LiveCard',
  props: {
    liveId: String,
    liveImg: String,
    liveTitle: String,
    liveUrl: String,
  },
  data () {
    return {
    }
  },
  setup () {
    const { redirectTo } = useNavigation();
    return {
      redirectTo
    }
  },
}
</script>

<style lang="less" scoped>
.live-card {
  width: 297px;
  height: 240px;
  padding: 7px 6px;
  border: 1px solid #E0E0E0;
  border-radius: 12px;

  .pic {
    width: 100%;
    height: 160px;
    position: relative;

    &.link {
      cursor: pointer;
    }

    .progress {
      height: 24px;
      padding: 4px 8px;
      line-height: 16px;
      font-size: 14px;
      font-weight: 400;
      color: @white;
      background: rgba(0,0,0,0.7);
      border-radius: 6px;
      position: absolute;
      bottom: 12px;
      right: 6px;
    }

    img {
      width: 100%;
      height: 100%;
      border-radius: 12px;
    }
  }

  .name {
    height: 48px;
    line-height: 20px;
    font-size: 16px;
    color: @font-black;
    padding-top: 10px;
    overflow: hidden;
    text-overflow: ellipsis;

    &.link {
      cursor: pointer;
    }
  }
}
</style>
